﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HealthCenter.ciic;
using System.ServiceModel;

namespace HealthCenter
{
    public class CiicHelper
    {
        //const string endpoint = "http://10.140.75.151:8001/ws/rxd_national.asmx";
        //const string endpoint = "http://jsw2.xh.sh.cn/ws/RXD_National.asmx";
        public static List<ApparatusReport> FindReports(DateTime? start, DateTime? end, bool? reported, int? id)
        {
            List<ApparatusReport> reports = new List<ApparatusReport>();
            try
            {
                RXD_NationalSoapClient client = new RXD_NationalSoapClient("RXD_NationalSoap",GlobalInfo.NationalSearchServiceUrl);
                DataTable table = client.GetWaitReportInfo(start, end);
                if (table != null)
                {
                    DataColumnCollection cols = table.Columns;
                    DataRowCollection rows = table.Rows;
                    foreach (DataRow row in rows)
                    {
                        ApparatusReport report = new ApparatusReport();

                        report.ID = row["id"].ToString();
                        report.A0 = row["A0"].ToString();
                        report.A1 = row["A1"].ToString();
                        report.A2 = row["A2"].ToString();
                        report.A3 = row["A3"].ToString();
                        report.A4 = row["A4"].ToString();
                        report.B5 = row["B5"].ToString();
                        report.B6 = row["B6"].ToString();
                        report.B7 = row["B7"].ToString();
                        report.B8 = row["B8"].ToString();
                        report.B91 = row["B91"].ToString();
                        report.B92 = row["B92"].ToString();
                        report.B93 = row["B93"].ToString();
                        report.B94 = row["B94"].ToString();
                        report.B95 = row["B95"].ToString();
                        report.B96 = row["B96"].ToString();
                        report.B97 = row["B97"].ToString();
                        report.C10 = row["C10"].ToString();
                        report.C11 = row["C11"].ToString();
                        report.C12 = row["C12"].ToString();
                        report.C13 = row["C13"].ToString();
                        report.C14 = row["C14"].ToString();
                        report.C15 = row["C15"].ToString();
                        report.C16 = row["C16"].ToString();
                        report.C17 = row["C17"].ToString();
                        report.C18 = row["C18"].ToString();
                        report.C19 = row["C19"].ToString();
                        report.C20 = row["C20"].ToString();
                        reports.Add(report);
                    }
                }
            }
            catch (EndpointNotFoundException)
            {
            }
            return reports;
        }

        public static bool UpdateReportAsReportedById(string id)
        {
            RXD_NationalSoapClient client = new RXD_NationalSoapClient("RXD_NationalSoap", GlobalInfo.NationalSearchServiceUrl);
            client.UpdateLineStatus(id);
            return true;
        }
    }

    public class ApparatusReport
    {
        public string ID { get; set; }
        public string A0 { get; set; }
        public string A1 { get; set; }
        public string A2 { get; set; }
        public string A3 { get; set; }
        public string A4 { get; set; }
        public string B5 { get; set; }
        public string B6 { get; set; }
        public string B7 { get; set; }
        public string B8 { get; set; }
        public string B91 { get; set; }
        public string B92 { get; set; }
        private string b93;
        public string B93 
        {
            get
            {
                return b93;
            }
            set
            {
                b93 = value == null?"":value.Replace("/", "");
                if (b93.Length > 100)
                {
                    b93 = b93.Substring(0, 100);
                }
            }
        }
        public string B94 { get; set; }
        public string B95 { get; set; }
        public string B96 { get; set; }
        public string B97 { get; set; }
        public string C10 { get; set; }
        public string C11 { get; set; }
        public string C12 { get; set; }
        public string C13 { get; set; }
        public string C14 { get; set; }
        public string C15 { get; set; }
        public string C16 { get; set; }
        public string C17 { get; set; }
        public string C18 { get; set; }
        private string c19;
        public string C19 
        {
            get
            {
                return c19;
            }
            set
            {
                c19 = value==null?"":value.Replace("/", "");
            }
        }
        public string C20 { get; set; }
        public bool Uploaded { get; set; }
    }
}
